<?php

namespace app\flow\controller;

use Controller;

class faceControl extends Controller
{
    function getDeviceFace()
    {
        $page = $this->ioMust('page');
        $keywords = $this->ioGet('keywords');
        if (empty($keywords)) {
            $jsonQuery = "{\"version\": \"0.2\",\"cmd\": \"request persons\",\"role\": -1,\"page_no\": {$page},\"page_size\": 20,\"feature_flag\": 0,\"image_flag\": 1,\"query_mode\": 0}";
        } else {
            $jsonQuery = "{\"version\": \"0.2\",\"cmd\": \"request persons\",\"role\": -1,\"page_no\": {$page},\"page_size\": 20,\"feature_flag\": 0,\"image_flag\": 1,\"query_mode\": 0,\"condition\": {\"person_id\": \"{$keywords}\"}}";
        }
        $ip = $this->ioMust('ip');
        $port = $this->ioMust('port');
        $jsonListStr = $this->curlPost("http://{$ip}:{$port}", $jsonQuery, true);
        $jsonList = json5_decode($jsonListStr, true);
        $jsonList['persons'] = filterListField($jsonList['persons'], ['id', 'name', 'reg_images']);
        return $this->ok($jsonList['persons'], $jsonList['total']);
    }
}